package com.msb.sentinel.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/****************************************************
 * 熔断练习
 *
 * @author lbf
 * @date 2025/6/24 14:26
 ****************************************************/
@RestController
public class CircuitBreakerController {

    @GetMapping("/breakerA")
    public String breakerTest(){

        //睡眠，模拟慢执行
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        return "*********************** breakerA";
    }

    /**
     * 异常比例/异常数
     * @return
     */
    @GetMapping("/breakerB")
    public String breakerTestB(Integer id){

        //模拟异常
        if(id != null && id >1){
            throw new RuntimeException("异常数");
        }

       return  "*********************** breakerB";
    }
}
